# Maintainer: Sergej Pupykin <arch+pub@sergej.pp.ru>

pkgname=('psi' 'psi-nowebengine')
pkgver=1.5
pkgrel=3
pkgdesc="Powerful XMPP (Jabber) client (Qt, C++) designed for power users"
url="https://psi-im.org"
license=('GPL2')
arch=('loong64' 'x86_64')
depends=('hunspell' 'qca' 'qt5-svg' 'qt5-webengine' 'qt5-x11extras' 'libidn')
makedepends=('cmake' 'qt5-multimedia')
source=("https://download.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tar.xz"
        "no-qca-qt4.patch"
        "qt-5.11.patch"
        "qt-5.15.patch"
        "appdata.patch")
sha256sums=('3167350fd43fab4dc948cb5179ca10159a7aa318472d1a8a7617e41f5aa8b5b7'
            'a6ea9a62100b6990b8a6c8590a6d0e9df095b99b6527bb5490a7fd3f6929ac23'
            'e56ec1a250488b2cf9d42887aac432ff2e0ef482eb7cc8500f3d52cb53949119'
            '5786131a946f8d50a0ef35dac6f3ea4b3abfe40c6e281cf3f52b22922850e7bc'
            '671bfebedbeebf3a159d3aa04caf62b8cb5f20bb31a95b0adb057619380cf6dd')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 <"$srcdir"/no-qca-qt4.patch
#  patch -p1 <"$srcdir"/qt-5.11.patch
#  patch -p1 <"$srcdir"/qt-5.15.patch

  # Upgrade appdata to meet with current spec
  # https://github.com/psi-im/psi/pull/590
#  patch -p1 <"$srcdir"/appdata.patch
}

build() {
  cd $pkgname-$pkgver
  mkdir -p build
  cd build
  cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ..
  make
  cd ..

  mkdir -p build-nowebengine
  cd build-nowebengine
  cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DENABLE_WEBKIT=OFF ..
  make
}

package_psi() {
  cd "$srcdir"/psi-$pkgver/build
  make DESTDIR="$pkgdir" install
  install -dm755 "$pkgdir/usr/include/psi/plugins"
  install -m644 ../src/plugins/include/*.h "$pkgdir/usr/include/psi/plugins"
  install -Dm644 ../$pkgbase.appdata.xml "$pkgdir/usr/share/metainfo/$pkgbase.appdata.xml"
}

package_psi-nowebengine() {
  pkgdesc+=" without WebEngine support"
  depends=('hunspell' 'minizip' 'qca-qt5' 'qt5-svg' 'qt5-x11extras' 'libidn')
  provides=("$pkgbase=$pkgver")
  conflicts=("$pkgbase")
  replaces=('psi-nowebkit')

  cd "$srcdir"/psi-$pkgver/build-nowebengine
  make DESTDIR="$pkgdir" install
  install -dm755 "$pkgdir/usr/include/psi/plugins"
  install -m644 ../src/plugins/include/*.h "$pkgdir/usr/include/psi/plugins"

  # Ignore package by AppStream to avoid duplicated IDs
  echo 'X-AppStream-Ignore=true' >> "$pkgdir/usr/share/applications/$pkgbase.desktop"
}
